{
  LX Deform module

  Based on modo's SDK lxdeform.h which is:

  Copyright (c) 2008-2012 Luxology LLC

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the "Software"),
  to deal in the Software without restriction, including without limitation
  the rights to use, copy, modify, merge, publish, distribute, sublicense,
  and/or sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.   Except as contained
  in this notice, the name(s) of the above copyright holders shall not be
  used in advertising or otherwise to promote the sale, use or other dealings
  in this Software without prior written authorization.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
}

{
  Copyright (c) 2012 David Ballesteros and Jameel Halabi

  This unit is part of the BLAISEmodo wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit Lx_Deform;

{$mode objfpc}{$H+}

interface

uses
  Lx_Result, Lx_VMath, LX_Mesh, Lx_Action;

const
  LXa_DEFORMERSERVICE                         = 'deformerservice';

  LXeDEFORM_DIFFERENT                         = LXeEVAL_DIFFERENT;

  LXfDEFORMATION_NONLINEAR                    = $01;
  LXfDEFORMATION_RIGIDXFRM                    = $02;

  LXfDEFORMER_NO_WEIGHT                       = $01 ;
  LXfDEFORMER_NO_OFFSET                       = $02 ;
  LXfDEFORMER_REQ_WEIGHT                      = $08 ;
  LXfDEFORMER_REQ_OFFSET                      = $10 ;
  LXfDEFORMER_IS_FALLOFF                      = $20 ;
  LXfDEFORMER_USE_LINEAR                      = $100;

  LXfITEMINF_POSITION                         = $01;
  LXfITEMINF_ROTATION                         = $02;
  LXfITEMINF_SCALE                            = $04;
  LXfITEMINF_PROBEWEIGHTS                     = $08;

  LXsITYPE_FALLOFF                            = 'falloff';

  LXsICHAN_FALLOFF_FALLOFF                    = 'falloffObj'   ;
  LXsICHAN_FALLOFF_DEFORMER                   = 'deformerObj'  ;
  LXsICHAN_FALLOFF_FALLENAB                   = 'enableFalloff';
  LXsICHAN_FALLOFF_DEFORMENAB                 = 'enableDeform' ;
  LXsICHAN_FALLOFF_STRENGTH                   = 'strength'     ;
  LXsICHAN_FALLOFF_INVERT                     = 'invert'       ;

  LXsPKG_DEFORMATION_CHANNEL                  = 'deformation.channel';
  LXsPKG_DEFORMER_CHANNEL                     = 'deformer.channel'   ;
  LXsPKG_DEFORMER_FLAGS                       = 'deformer.flags'     ;
  LXsPKG_DEFORMER_CREATECMD                   = 'deformer.create'    ;

  LXsITYPE_DEFORMGROUP                        =  'deformGroup';

  LXsICHAN_DEFORMGROUP_DEFORMER               = 'deformObj'    ;
  LXsICHAN_DEFORMGROUP_ENABLE                 = 'enable'       ;
  LXsICHAN_DEFORMGROUP_INTERPOLATION          = 'interpolation';
  LXsICHAN_DEFORMGROUP_LIMITENABLE            = 'limitEnable'  ;
  LXsICHAN_DEFORMGROUP_LIMITMAX               = 'limitMax'     ;
  LXsICHAN_DEFORMGROUP_THRESHOLD              = 'threshold'    ;
  LXsICHAN_DEFORMGROUP_SHARPNESS              = 'sharpness'    ;

  LXsICVAL_DEFORMGROUP_INTERPOLATION_LOCAL    = 'local' ;
  LXsICVAL_DEFORMGROUP_INTERPOLATION_LINEAR   = 'linear';
  LXsICVAL_DEFORMGROUP_INTERPOLATION_DQS      = 'dqs'   ;

  LXsITYPE_DEFORMFOLDER                       = 'deformFolder';

  LXsICHAN_DEFORMFOLDER_ENABLE                ='enable';

  LXsITYPE_ITEMINFLUENCE                      = 'itemInfluence';

  LXsICHAN_ITEMINFLUENCE_ITEMINF              = 'itemInf'      ;
  LXsICHAN_ITEMINFLUENCE_ENABLE               = 'enable'       ;
  LXsICHAN_ITEMINFLUENCE_INTERPOLATION        = 'interpolation';
  LXsICHAN_ITEMINFLUENCE_POSENABLE            = 'posEnable'    ;
  LXsICHAN_ITEMINFLUENCE_ROTENABLE            = 'rotEnable'    ;
  LXsICHAN_ITEMINFLUENCE_SCLENABLE            = 'sclEnable'    ;
  LXsICHAN_ITEMINFLUENCE_SAMPLEWEIGHT         = 'sampleWeight' ;

  LXsICVAL_ITEMINFLUENCE_INTERPOLATION_LOCAL  = 'local' ;
  LXsICVAL_ITEMINFLUENCE_INTERPOLATION_LINEAR = 'linear';

  LXu_DEFORMATION           = '{F5705327-7382-47C5-8D7B-AF2CC18B3E8A}';
  LXu_DEFORMER              = '{F029A563-A937-4DB2-992E-1592081F64CC}';
  LXu_DEFORMERSERVICE       = '{8267068C-FDBB-430A-8230-BE64F72CE3E3}';
  LXu_FALLOFF               = '{B7D1DEF8-1F45-4924-B518-E2F2A76D0259}';
  LXu_GROUPDEFORMER         = '{4BC04F3F-29FC-4EA3-B090-10280331C757}';
  LXu_ITEMINFLUENCE         = '{2141BD0B-DEFC-4A92-A4A5-30760C09F18B}';
  LXu_MESHINFLUENCE         = '{D70AA410-75BB-480E-90E2-17E2059EB40B}';
  LXu_WEIGHTMAPDEFORMERITEM = '{A9C81E0B-20F0-4D8B-838B-B593EAF3DFB8}';

type
  PLXtDeformElt = ^LXtDeformElt;
  LXtDeformElt  = Pointer      ;

  ILxFalloff = interface
  [LXu_FALLOFF]
    function Bounds   (      Box      : PLXtBBox  ) : LxResult;
    function WeightF  (const Position : LXtFVector) : LxResult;
    function WeightRun(const Pos      : PPSingle  ;
                             Weight   : PSingle   ;
                             Num      : UInt32    ) : LxResult;
  end;

  ILxDeformation = interface
  [LXu_DEFORMATION]
    function  Flags                                  : UInt32  ;
    function  Transform(      Xfrm     : LXtMatrix4) : LxResult;
    procedure OffsetF  (const Position : LXtFVector;
                              Weight   : Single    ;
                              Offset   : LXtFVector) ;
    procedure OBSOLETE                               ;
    function  OffsetRun(const Pos      : PPsingle  ;
                        const Weight   : PSingle   ;
                              Offset   : PPSingle  ;
                              Num      : UInt32    ) : LxResult;
  end;

  ILxDeformer = interface
  [LXu_DEFORMER]
    function  Flags                                             : UInt32      ;
    function  PartitionCount                                    : UInt32      ;
    function  EnumeratePartition(      Visitor : IUnknown     ;
                                       Part    : UInt32       ) : LxResult    ;
    function  Element           (      Segment : PUInt32      ) : LXtDeformElt;
    function  SetPartition      (      Part    : UInt32       ) : LxResult    ;
    function  Weight            (      Elt     : LXtDeformElt ;
                                       Pos     : LXtFVector   ) : Single      ;
    procedure Offset            (      Elt     : LXtDeformElt ;
                                       Weight_ : Single       ;
                                       Pos     : LXtFVector   ;
                                       Offset  : LXtFVector   )               ;
    function  WeightRun         (      Segment : UInt32       ;
                                 const Elt     : PLXtDeformElt;
                                 const Pos     : PPSingle     ;
                                       Weight_ : PSingle      ;
                                       Num     : UInt32       ) : LxResult    ;
    function  OffsetRun         (      Segment : UInt32       ;
                                 const Elt     : PLXtDeformElt;
                                 const Pos     : PPSingle     ;
                                 const Weight_ : PSingle      ;
                                       Offset_ : PPSingle     ;
                                       Num     : UInt32       ) : LxResult    ;
  end;

  ILxMeshInfluence = interface
  [LXu_MESHINFLUENCE]
    function MeshCount                               : UInt32  ;
    function MeshByIndex   (    Index  : UInt32    ;
                            out VObj               ) : LxResult;
    function PartitionIndex(    Index  : UInt32    ) : UInt32  ;
    function SetMesh       (    Index  : UInt32    ;
                                Mesh   : IUnknown  ;
                                Item   : IUnknown  ) : LxResult;
    function SetTransform  (    Index  : UInt32    ;
                                Xfrm   : LXtMatrix4) : LxResult;
    function MeshChange    (    Index  : UInt32    ;
                                Change : LxResult  ) : LxResult;
  end;

  ILxItemInfluence = interface
  [LXu_ITEMINFLUENCE]
    function HasItems                               : LxResult;
    function Enumerate     (    Visitor : IUnknown) : LxResult;
    function GetItem       (out VObj              ) : LxResult;
    function AllowTransform(    Index   : UInt32  ;
                                Flags   : PUInt32 ) : LxResult;
  end;

  ILxGroupDeformer = interface
  [LXu_GROUPDEFORMER]
    function DeformerCount                              : UInt32  ;
    function DeformerByIndex(    Index     : UInt32   ;
                             out VObj                 ) : LxResult;
    function PointEffect    (    MeshIndex : UInt32   ;
                                 Point     : PLXtPoint;
                                 Deformer  : PUInt32  ;
                                 Weight    : Psingle  ;
                                 Count     : Psingle  ;
                                 Max       : UInt32   ) : LxResult;
  end;

  ILxWeightMapDeformerItem = interface
  [LXu_WEIGHTMAPDEFORMERITEM]
    function GetMapName(ChanRead : IUnknown ;
                        Buf      : PChar    ;
                        Len      : UInt32   ) : LxResult;
    function GetColor  (ChanRead : IUnknown ;
                        Col      : LXtVector) : LxResult;
  end;

  ILxDeformerService = interface
  [LXu_DEFORMERSERVICE]
    function  ScriptQuery
              (out VObj                   ) : LxResult    ;

    function  DeformerFlags
              (    Item     : IUnknown    ;
                   Flags    : PUInt32     ) : LxResult    ;

    function  DeformerChannel
              (    Item     : IUnknown    ;
                   Index    : PUInt32     ) : LxResult    ;

    function  MergeChangeState
              (    C1       : LxResult    ;
                   C2       : LxResult    ) : LxResult    ;

    function  MeshCount
              (    DefItem  : IUnknown    ;
                   Count    : PUint32     ) : LxResult    ;

    function  MeshByIndex
              (    DefItem  : IUnknown    ;
                   Index    : PUint32     ;
               out VObj                   ) : LxResult    ;

    function  GroupDeformer
              (    DGroup   : IUnknown    ;
                   ChanRead : IUnknown    ;
               out VObj                   ) : LxResult    ;

    function  DeformerDeformationItem
              (    DefItem  : IUnknown    ;
               out VObj                   ) : LxResult    ;

    procedure InvalidateTargets
              (    Scene    : IUnknown    )               ;

    function  ItemToDeformElt
              (    Item     : IUnknown    ) : LXtDeformElt;

    function  DeformEltToItem
              (    Elt      : LXtDeformElt) : IUnknown    ;
  end;

function LXeDEFORM_IDENTICAL  : LxResult;
function LXeDEFORM_NEWOFFSET  : LxResult;
function LXeDEFORM_NEWWEIGHT  : LxResult;
function LXeDEFORM_AUTO_COLOR : LxResult;

implementation

function LXeDEFORM_IDENTICAL  : LxResult; inline;
begin
  Result := LXeEVAL_IDENTICAL;
end;
function LXeDEFORM_NEWOFFSET  : LxResult; inline;
begin
  Result := LXxGOODCODE(LXeSYS_DEFORM, 21);
end;
function LXeDEFORM_NEWWEIGHT  : LxResult; inline;
begin
  Result := LXxGOODCODE(LXeSYS_DEFORM, 22);
end;
function LXeDEFORM_AUTO_COLOR : LxResult; inline;
begin
  Result := LXxGOODCODE(LXeSYS_DEFORM, 12);
end;

end.

